﻿using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using IterationLife.Extensions.Dtos;
using IterationLife.FootballTeaching.Enums;
using Util.Domains;
using Util.Domains.Auditing;

namespace IterationLife.FootballTeaching.Models
{
    /// <summary>
    /// 课时
    /// </summary>
    [Description("课时")]
    public partial class Lesson : AggregateRoot<Lesson>, IDelete, IAudited
    {
        /// <summary>
        /// 初始化课时
        /// </summary>
        public Lesson() : this(Guid.Empty)
        {
        }

        /// <summary>
        /// 初始化课时
        /// </summary>
        /// <param name="id">课时标识</param>
        public Lesson(Guid id) : base(id)
        {
            Banner = new Resources();
            Video = new Resources();
        }

        /// <summary>
        /// 章节编号
        /// </summary>
        [Required(ErrorMessage = "章节编号不能为空")]
        public Guid? ChapterId { get; set; }
        /// <summary>
        /// 名称
        /// </summary>
        [Required(ErrorMessage = "名称不能为空")]
        [StringLength(50, ErrorMessage = "名称输入过长，不能超过50位")]
        public string Name { get; set; }
        /// <summary>
        /// 封面图
        /// </summary>
        [NotMapped]
        public Resources Banner { get; set; }
        /// <summary>
        /// 封面图
        /// </summary>
        [StringLength(500, ErrorMessage = "封面图输入过长，不能超过500位")]
        public string BannerJsonStr
        {
            get => Util.Json.ToJson(Banner);
            set => Banner = Util.Json.ToObject<Resources>(value);
        }
        /// <summary>
        /// 视频
        /// </summary>
        [NotMapped]
        public Resources Video { get; set; }
        /// <summary>
        /// 视频
        /// </summary>
        [Required(ErrorMessage = "视频不能为空")]
        [StringLength(500, ErrorMessage = "视频输入过长，不能超过500位")]
        public string VideoJsonStr
        {
            get => Util.Json.ToJson(Video);
            set => Video = Util.Json.ToObject<Resources>(value);
        }
        /// <summary>
        /// 难度
        /// </summary>
        [Required(ErrorMessage = "难度不能为空")]
        public DifficultyType? Difficulty { get; set; }
        /// <summary>
        /// 要求
        /// </summary>
        [Required(ErrorMessage = "要求不能为空")]
        [StringLength(255, ErrorMessage = "要求输入过长，不能超过255位")]
        public string Requirement { get; set; }
        /// <summary>
        /// 内容
        /// </summary>
        [Required(ErrorMessage = "内容不能为空")]
        public string Content { get; set; }
        /// <summary>
        /// 排序号
        /// </summary>
        [Required(ErrorMessage = "排序号不能为空")]
        public int? SortId { get; set; }
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime? CreationTime { get; set; }
        /// <summary>
        /// 创建人
        /// </summary>
        public Guid? CreatorId { get; set; }
        /// <summary>
        /// 最后修改时间
        /// </summary>
        public DateTime? LastModificationTime { get; set; }
        /// <summary>
        /// 最后修改人
        /// </summary>
        public Guid? LastModifierId { get; set; }
        /// <summary>
        /// 是否删除
        /// </summary>
        [Required(ErrorMessage = "是否删除不能为空")]
        public bool IsDeleted { get; set; }

        /// <summary>
        /// 章节
        /// </summary>
        public virtual Chapter Chapter { get; set; }

        /// <summary>
        /// 添加描述
        /// </summary>
        protected override void AddDescriptions()
        {
            AddDescription("课时编号", Id);
            AddDescription("章节编号", ChapterId);
            AddDescription("名称", Name);
            AddDescription("封面图", Banner);
            AddDescription("视频", Video);
            AddDescription("难度", Difficulty);
            AddDescription("要求", Requirement);
            AddDescription("内容", Content);
            AddDescription("排序号", SortId);
            AddDescription("创建时间", CreationTime);
            AddDescription("创建人", CreatorId);
            AddDescription("最后修改时间", LastModificationTime);
            AddDescription("最后修改人", LastModifierId);
        }

        /// <summary>
        /// 添加变更列表
        /// </summary>
        protected override void AddChanges(Lesson newEntity)
        {
            AddChange("Id", "课时编号", Id, newEntity.Id);
            AddChange("ChapterId", "章节编号", ChapterId, newEntity.ChapterId);
            AddChange("Name", "名称", Name, newEntity.Name);
            AddChange("Banner", "封面图", Banner, newEntity.Banner);
            AddChange("Video", "视频", Video, newEntity.Video);
            AddChange("Difficulty", "难度", Difficulty, newEntity.Difficulty);
            AddChange("Requirement", "要求", Requirement, newEntity.Requirement);
            AddChange("Content", "内容", Content, newEntity.Content);
            AddChange("SortId", "排序号", SortId, newEntity.SortId);
            AddChange("CreationTime", "创建时间", CreationTime, newEntity.CreationTime);
            AddChange("CreatorId", "创建人", CreatorId, newEntity.CreatorId);
            AddChange("LastModificationTime", "最后修改时间", LastModificationTime, newEntity.LastModificationTime);
            AddChange("LastModifierId", "最后修改人", LastModifierId, newEntity.LastModifierId);
        }
    }
}